package order

import (
	"API/client"
	"API/request"
	"API/response"
	"common/utils"
	"github.com/gin-gonic/gin"
	order "order_server/proto"
)

func OrderList(c *gin.Context) {
	var req request.OrderListRequest
	if err := c.ShouldBind(&req); err != nil {
		response.CurrencyErrResponse(c, 400, err.Error())
		return
	}

	userId := c.GetUint("userId")
	list, err := client.OrderList(c, &order.OrderListRequest{
		Uid:         int64(userId),
		Status:      req.Status,
		Pages:       req.Page,
		PagePerNums: req.PageSize,
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, utils.CutOutRpcError(err.Error()))
		return
	}

	response.CurrencySuccessResponse(c, "订单展示成功", map[string]interface{}{
		"OrderList": list.List,
		"Total":     list.Total,
	})
}
